﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExamAnalysis.Model;

namespace ExamAnalysis
{
    public partial class DataDemo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (ExamAnalysisDataContext db = new ExamAnalysisDataContext())
                {
                    //LinQ方法一
                    Demo2.DataSource = db.ClassInfo.Where(p => p.IsValid && p.SchoolID != null)
                        .Select(p => new { p.ClassName, p.EnrollYear, p.ClassCode })
                        .OrderBy(p => p.EnrollYear);
                    //LinQ方法二（等价）
                    Demo2.DataSource = from p in db.ClassInfo
                                       where p.IsValid && p.SchoolID != null
                                       orderby p.EnrollYear
                                       select new { p.ClassName, p.EnrollYear, p.ClassCode };
                    Demo2.DataBind();
                }
            }
        }
    }
}